<?php 

require_once("form/test.php");

class BooleanForm extends Form {
	
	public function __construct(){
		parent::__construct(array(
			"published" => new BooleanField(),
		));
	}
	
}

class BooleanFieldTest extends Test {
	
	public function run(){
		$form = new BooleanForm();
		$this->tags($form);
		$this->invalid($form);
		$this->valid($form);
	}
	
	private function tags($form){
		$this->assertEquals($form->render("published"), "<input type=\"checkbox\" name=\"published\" id=\"published\" value=\"1\" />");
		$form->populate(array("published" => TRUE));
		$this->assertEquals($form->render("published"), "<input type=\"checkbox\" name=\"published\" id=\"published\" value=\"1\" checked=\"checked\" />");
		$form->clean();
	}
	
	private function invalid($form){
		$this->assertEquals(FALSE, $form->isValid(), "Form is not valid");
		$this->assertTrue(in_array("published", $form->errors), "Published contains error");
		$this->assertTrue($form->containsError("published"), "Published contains error");
		$this->assertEquals($form->getValue("published"), FALSE);
		$form->clean();
	}
	
	private function valid($form){
		$form->populate(array("published" => TRUE));
		$this->assertTrue($form->isValid(), "Form valid");
		$this->assertFalse(in_array("published", $form->errors), "Published does NOT contain error cause it's valid");
		$this->assertFalse($form->containsError("published"), "Published does NOT contain error cause it's valid");
		$this->assertNotEmpty($form->getValue("published"));
		$this->assertEquals($form->getValue("published"), TRUE);
		$form->clean();
	}

}

$test = new BooleanFieldTest();
$test->run();